#include <bits/stdc++.h>
using namespace std;
int t;
const int N=100010;
int n,m,l,vv;
int d[N];
int v[N];
int a[N];
int p[N];
int cnt=0;
int cnt2=0;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        int ans1=0;
        cin>>n>>m>>l>>vv;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]!=0)
            {
                cnt+=1;
            }
            if(a[i]>=0)
            {
                cnt2+=1;
            }
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
        }
        if(cnt==0)
        {
            for(int i=1;i<=n;i++)
            {
                if(v[i]>vv and d[i]<=p[m])
                {
                    ans1++;
                }
            }
            if(ans1==0)
            {
                cout<<ans1<<" "<<m<<"\n";
            }
            else
            {
                cout<<ans1<<" "<<m-1<<"\n";
            }
        }
        else if(cnt2==0)
        {
            for(int i=1;i<=n;i++)
            {
                if(sqrt(pow(v[i],2)+2*a[i]*p[1])>vv and d[i]<=p[m])
                {
                    ans1++;
                }
            }
            if(ans1==0)
            {
                cout<<ans1<<" "<<m<<"\n";
            }
            else
            {
                cout<<ans1<<" "<<m-1<<"\n";
            }
        }
    }
    return 0;
}
